<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer <81818832@qq.com>
// +----------------------------------------------------------------------
namespace app\home\controller;

use think\Db;

class Platform extends Base
{
    //文章内页
    public function index()
    {
		$page=input('page',1);
		$news=Db::name('platform')->where(array('platform_id'=>input('id')))->find();
		if(empty($news)){
		    $this->error(lang('operation not valid'));
		}
		
		$menu=Db::name('menu')->find($news['platform_cid']);
		if(empty($menu)){
		    $this->error(lang('operation not valid'));
		}
		$tplname=$menu['menu_newstpl'];
    	$tplname=$tplname?$tplname:'news';
		//自行根据网站需要考虑，是否需要判断
		//$can_do=check_user_action('news'.input('id'),0,false,60);
		$plan=Db::name('plan')->where(array('platform_id'=>input('id')))->select();
		$this->assign('plan',$plan);
		//var_dump($this->user);
		if(!empty($this->user['member_list_id'])){
			$member_list_id=$this->user['member_list_id'];
		}else{
			$member_list_id=0;
		}
		$myinreg=Db::name('inreg')->where(array('platform_id'=>input('id'),'member_list_id'=>$member_list_id))->select();
		foreach($myinreg as $k=>$v){
			$plan_name=Db::name('plan')->find($v['plan_id']);
			$myinreg[$k]['plan_name']=$plan_name['name'];
		}
		//var_dump($myinreg);
		$this->assign('myinreg',$myinreg);
		
		$this->assign($news);
		$this->assign('menu',$menu);
		return $this->view->fetch(":$tplname");
    }
	
    public function doinreg()
    {
	    $this->check_login();
    	$plan_id=input('plan_id',0,'intval');
		$phone=input('phone');
    	$jine=input('jine');
    	$tz_date=input('tz_date');
    	$qx_date=input('qx_date');
		$platform_id=input('platform_id',0,'intval');
		if(empty($plan_id)){
			$this->error("请选择方案");
		}
    	if(empty($phone)){
			$this->error("请输入手机号码");
		}
    	if(empty($jine)){
			$this->error("请输入投资金额");
		}
    	if(empty($tz_date)){
			$this->error("请输入投资日期");
		}
    	if(empty($qx_date)){
			$this->error("请输入起息日期");
		}
		$new_inreg=array(
            'member_list_id'=>$this->user['member_list_id'],
            'plan_id'=>$plan_id,
            'phone'=>$phone,
            'jine'=>$jine,
            'platform_id'=>$platform_id,
            'tz_date'=>strtotime($tz_date." 00:00:00"),
            'qx_date'=>strtotime($qx_date." 00:00:00"),
            'ctime'=>time(),
        );
		$doinreg=Db::name("inreg")->insert($new_inreg);
    	if($doinreg){
			$this->success("投资登记成功");
    	}else{
    		$this->error("投资登记失败");
    	}
    }
    
}
